package com.resourcestore.action;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.resourcestore.utils.CommonUtil;
import com.resourcestore.action.BaseAction;
import com.resourcestore.dao.*;
import com.resourcestore.model.*;
import com.resourcestore.utils.tag.Pagination;

public class MainAction extends BaseAction {

	private List<MajorGroup> listMajorGroup;
	private MajorGroupDao majorGroupDao = new MajorGroupDao();
	private MajorDao majorDao = new MajorDao();
	private List<Major> listMajor;
	private CourseCategoryDao courseCategoryDao = new CourseCategoryDao();
	private List<CourseCategory> listCourseCate;
	private CourseDao courseDao = new CourseDao();
	private List<Course> listCourse;
	private MajorGroup majorGroup;
	private Pagination pagination = new Pagination();
	private Major major;
	private ExcellentCourse excellentCourse;
	private ExcellentCourseDao excellentCourseDao = new ExcellentCourseDao();
	private List<MajorFileSrcCate> listMajorFileSrcCate;
	private MajorFileSrcCateDao majorFileSrcCateDao = new MajorFileSrcCateDao();
	private MajorFileSrcCate majorFileSrcCate;
	private Announce announce;
	private List<Announce> listAnnounce;
	private AnnounceDao announceDao = new AnnounceDao();
	private List<CourseFileSrcCatePublic> listCourseFileSrcCatePublic;
	private CourseFileSrcCatePublicDao courseFileSrcCatePublicDao = new CourseFileSrcCatePublicDao();
	private CourseFileSrcCatePublic courseFileSrcCatePublic;

	private List<CourseTeaClassFK> listCourseTeaClassFK;
	private CourseTeaClassFKDao courseTeaClassFKDao = new CourseTeaClassFKDao();
	private CourseTeaClassFK courseTeaFK;
	private List<Department> listDepartment;
	private Department department;
	private DepartmentDao departmentDao = new DepartmentDao();

	/**
	 * 首页内容
	 * 
	 */
	public String indexContent() {
		
		listAnnounce = announceDao.selectAnnounce();

		for (int i = 0; i < listAnnounce.size(); i++) {
			try {
				listAnnounce.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtCreated()));
				listAnnounce.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return newpath("/Main/indexContent.jsp");
	}


	
	/**
	 * 查询返回List
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listAnnounce() {
		announce = new Announce();
		pagination.setTotal(announceDao.queryAnnounceNum(announce));
		listAnnounce = announceDao.selectAnnouncePage(announce, pagination);

		for (int i = 0; i < listAnnounce.size(); i++) {
			try {
				listAnnounce.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtCreated()));
				listAnnounce.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return "default";
	}

	/**
	 * 根据条件搜索，查询返回List带分页
	 * 
	 * @throws ParseException
	 * 
	 */
	public String searchListAnounce() {

		// 对内容进行urldecoder解码
		try {
			announce.setAnnounceName(new String(announce.getAnnounceName()
					.getBytes("iso-8859-1"), "UTF-8"));
			announce.setAnnounceContent(new String(announce
					.getAnnounceContent().getBytes("iso-8859-1"), "UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		pagination.setTotal(announceDao.queryAnnounceNum(announce));
		listAnnounce = announceDao.selectAnnouncePage(announce, pagination);

		// 将bigint数字处理为时间格式

		for (int i = 0; i < listAnnounce.size(); i++) {
			try {
				listAnnounce.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtCreated()));
				listAnnounce.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listAnnounce.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return newpath("/Main/listAnnounce.jsp");
	}
	
	
	/**
	 * 查询专业群信息BYid
	 * 
	 */
	public String infoMajorGroupReadById() {
		majorGroup = majorGroupDao.selectMajorGroupById(majorGroup);
		return newpath("/ExpertMain/infoMajorGroupReadById.jsp");
	}

	/**
	 * 查询专业信息BYid
	 * 
	 */
	public String infoMajorReadById() {
		major = majorDao.selectMajorById(major);
		return newpath("/ExpertMain/infoMajorReadById.jsp");
	}

	/**
	 * 查询精品课程信息BYid
	 * 
	 */
	public String infoExcellentCourseReadById() {
		excellentCourse = excellentCourseDao
				.selectExcellentCourseById(excellentCourse);
		return newpath("/ExpertMain/infoExcellentCourseReadById.jsp");
	}

	public List<MajorGroup> getListMajorGroup() {
		return listMajorGroup;
	}

	public void setListMajorGroup(List<MajorGroup> listMajorGroup) {
		this.listMajorGroup = listMajorGroup;
	}

	public List<Major> getListMajor() {
		return listMajor;
	}

	public void setListMajor(List<Major> listMajor) {
		this.listMajor = listMajor;
	}

	public List<CourseCategory> getListCourseCate() {
		return listCourseCate;
	}

	public void setListCourseCate(List<CourseCategory> listCourseCate) {
		this.listCourseCate = listCourseCate;
	}

	public List<Course> getListCourse() {
		return listCourse;
	}

	public void setListCourse(List<Course> listCourse) {
		this.listCourse = listCourse;
	}

	public MajorGroup getMajorGroup() {
		return majorGroup;
	}

	public void setMajorGroup(MajorGroup majorGroup) {
		this.majorGroup = majorGroup;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public Major getMajor() {
		return major;
	}

	public void setMajor(Major major) {
		this.major = major;
	}

	public ExcellentCourse getExcellentCourse() {
		return excellentCourse;
	}

	public void setExcellentCourse(ExcellentCourse excellentCourse) {
		this.excellentCourse = excellentCourse;
	}

	public List<MajorFileSrcCate> getListMajorFileSrcCate() {
		return listMajorFileSrcCate;
	}

	public void setListMajorFileSrcCate(
			List<MajorFileSrcCate> listMajorFileSrcCate) {
		this.listMajorFileSrcCate = listMajorFileSrcCate;
	}

	public MajorFileSrcCate getMajorFileSrcCate() {
		return majorFileSrcCate;
	}

	public void setMajorFileSrcCate(MajorFileSrcCate majorFileSrcCate) {
		this.majorFileSrcCate = majorFileSrcCate;
	}

	public Announce getAnnounce() {
		return announce;
	}

	public void setAnnounce(Announce announce) {
		this.announce = announce;
	}

	public List<Announce> getListAnnounce() {
		return listAnnounce;
	}

	public void setListAnnounce(List<Announce> listAnnounce) {
		this.listAnnounce = listAnnounce;
	}

	public List<CourseFileSrcCatePublic> getListCourseFileSrcCatePublic() {
		return listCourseFileSrcCatePublic;
	}

	public void setListCourseFileSrcCatePublic(
			List<CourseFileSrcCatePublic> listCourseFileSrcCatePublic) {
		this.listCourseFileSrcCatePublic = listCourseFileSrcCatePublic;
	}

	public CourseFileSrcCatePublic getCourseFileSrcCatePublic() {
		return courseFileSrcCatePublic;
	}

	public void setCourseFileSrcCatePublic(
			CourseFileSrcCatePublic courseFileSrcCatePublic) {
		this.courseFileSrcCatePublic = courseFileSrcCatePublic;
	}

	public List<CourseTeaClassFK> getListCourseTeaClassFK() {
		return listCourseTeaClassFK;
	}

	public void setListCourseTeaClassFK(
			List<CourseTeaClassFK> listCourseTeaClassFK) {
		this.listCourseTeaClassFK = listCourseTeaClassFK;
	}

	public CourseTeaClassFK getCourseTeaClassFK() {
		return courseTeaFK;
	}

	public void setCourseTeaClassFK(CourseTeaClassFK courseTeaFK) {
		this.courseTeaFK = courseTeaFK;
	}

	public List<Department> getListDepartment() {
		return listDepartment;
	}

	public void setListDepartment(List<Department> listDepartment) {
		this.listDepartment = listDepartment;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

}
